﻿using MyDLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace winform_用户界面客户端
{
    public static class GlobalValue
    {
        public static string Cur_DB_Path;
        public static string DB_Name = ".SBT";
        public static string DB_TempName = ".SBT-journal";//sqlite会自动生成的临时文件

                
        public static Dictionary<string, MySqlite> DB_List = new Dictionary<string, MySqlite>();
        public static MySqlite GetDB(string path)
        {
            if (DB_List.ContainsKey(path))
                return DB_List[path];
            else
                return null;
        }

        public static bool AddDB(string path,MySqlite m)
        {
            if (!DB_List.ContainsKey(path))
            {
                DB_List.Add(path, m);
            }
            else
                return false;
            return true;
        }
        /// <summary>
        /// 打开数据库文件
        /// </summary>
        /// <param name="dir_path">最后必须要有"\"</param>
        /// <returns></returns>
        public static MySqlite OpenDB(string dir_path)
        {
            if (!DB_List.ContainsKey(dir_path))
            {
                MySqlite m = new MySqlite();
                m.Create_Open_DB(dir_path + GlobalValue.DB_Name);
                DB_List.Add(dir_path, m);
                return m;
            }
            else
            {
                return DB_List[dir_path];
            }
            
        }
                
    }
}
